package com.enthusiasm.frame;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import com.enthusiasm.constants.SoundManager;
import com.enthusiasm.view.GameMenuView;
import com.waps.AdView;
import com.waps.AppConnect;
import com.young.R;

import dalvik.system.VMRuntime;

public class GameMenuActivity extends Activity {
	RelativeLayout frame;
	GameMenuView surfaceView;
	 private final static float TARGET_HEAP_UTILIZATION = 0.75f; 
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        /*广告添加*/
        AppConnect.getInstance(this);
        AppConnect.getInstance(this).setPushIcon(R.drawable.icon);//设置推送ICON
        AppConnect.getInstance(this).setPushAudio(false);//关闭推送声音
        
		frame = new RelativeLayout(this);
		surfaceView = new GameMenuView(this);
		frame.addView(surfaceView);
		
		LinearLayout container = new LinearLayout(this);
//		new AdView(this,container).DisplayAd(20);
		RelativeLayout.LayoutParams relative = new RelativeLayout.LayoutParams(
				ViewGroup.LayoutParams.FILL_PARENT,
				ViewGroup.LayoutParams.WRAP_CONTENT);
		relative.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
		container.setGravity(Gravity.CENTER_HORIZONTAL);
		container.setLayoutParams(relative);
		frame.addView(container);
		setContentView(frame);
		 VMRuntime.getRuntime().setTargetHeapUtilization(TARGET_HEAP_UTILIZATION);
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
		switch(resultCode){
		case 1:
			this.finish();
			break;
		}
		super.onActivityResult(requestCode, resultCode, data);
	}
	
	@Override
	protected void onPause() {
		super.onPause();
		SoundManager.getInstance(this).pauseBackgroundSound();
	}

	@Override
	protected void onResume() {
		super.onResume();
		if(SoundManager.getInstance(this).getIsMediaStop() == false)
			SoundManager.getInstance(this).resumeBackGroundSound();
	}
	
	@Override
	protected void onRestart() {
		super.onRestart();
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			Intent intent = new Intent(GameMenuActivity.this,GameQuitActivity.class);
			startActivityForResult(intent, 0);
		}
		return false;
	}
}
